home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWZoneSimple.z / RWZoneSimple
Encoding:
Text File  |  1998-10-30  |  16.5 KB  |  397 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWZoneSimple - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <time.h>
  13.  
  14.  
  15.  
  16.               #include <rw/zone.h>
  17.           RWZoneSimple myZone(USCentral);
  18.  
  19.  
  20.  
  21.  
  22. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  23.      RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee is an implementation of the abstract interface defined by
  24.      class RRRRWWWWZZZZoooonnnneeee.  It implements a simple daylight-saving time rule
  25.      sufficient to represent all historical U.S. conventions and many European
  26.      and Asian conventions.  It is table-driven and depends on parameters
  27.      given by the struct RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee,,,, which is described below.  Direct use
  28.      of RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee affords the most general interface to RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee.
  29.      However, a much simpler programmatic interface is offered, as illustrated
  30.      by the examples below.  Three instances of RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee are automatically
  31.      constructed at program startup, to represent UTC, Standard, and local
  32.      time.  They are available via calls to the static member functions
  33.      RRRRWWWWZZZZoooonnnneeee::::::::uuuuttttcccc(((()))), RRRRWWWWZZZZoooonnnneeee::::::::ssssttttaaaannnnddddaaaarrrrdddd(((()))), and RRRRWWWWZZZZoooonnnneeee::::::::llllooooccccaaaallll(((()))), respectively.
  34.      These member functions are set up according to the time zone facilities
  35.      provided in the execution environment (typically defined by the
  36.      environment variable TTTTZZZZ).  By default, if DST is observed at all, then
  37.      the local zone instance will use U.S. (RRRRWWWWZZZZoooonnnneeee::::::::NNNNooooAAAAmmmm) daylight-saving time
  38.      rules.  NNNNooootttteeee ffffoooorrrr ddddeeeevvvveeeellllooooppppeeeerrrrssss oooouuuuttttssssiiiiddddeeee NNNNoooorrrrtttthhhh AAAAmmmmeeeerrrriiiiccccaaaa:  for some time zones
  39.      this default will not be correct because these time zones rely on the C
  40.      standard global variable _ddddaaaayyyylllliiiigggghhhhtttt.  This variable is set whenever any
  41.      alternate time zone rule is available, whether it represents daylight-
  42.      saving time or not.  Also the periods of history affected by daylight-
  43.      saving time may be different in your time zone from those in North
  44.      America, causing the North American rule to be erroneously invoked.  The
  45.      best way to ensure that these default time zones are correct is to
  46.      construct an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee using an appropriate RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee and
  47.      initialize RRRRWWWWZZZZoooonnnneeee::llllooooccccaaaallll(((()))) and RRRRWWWWZZZZoooonnnneeee::::::::ssssttttdddd(((()))) with this value.  Other
  48.      instances of RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee may be constructed to represent other time
  49.      zones, and may be installed globally using RRRRWWWWZZZZoooonnnneeee static member functions
  50.      RRRRWWWWZZZZoooonnnneeee::::::::llllooooccccaaaallll((((ccccoooonnnnsssstttt RRRRWWWWZZZZoooonnnneeee****)))) and RRRRWWWWZZZZoooonnnneeee::::::::ssssttttaaaannnnddddaaaarrrrdddd((((ccccoooonnnnsssstttt RRRRWWWWZZZZoooonnnneeee****)))).
  51.  
  52. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  53.      None
  54.  
  55. EEEExxxxaaaammmmpppplllleeeessss
  56.      To install US Central time as your global "local" time use:
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.               RWZone::local(new RWZoneSimple(RWZone::USCentral));
  75.  
  76.  
  77.  
  78.  
  79.  
  80.      To install Hawaiian time (where daylight-saving time is not observed) one
  81.      would say,
  82.  
  83.               RWZone::local(new RWZoneSimple(RWZone::Hawaii, RWZone::NoDST));
  84.  
  85.  
  86.  
  87.  
  88.  
  89.      Likewise for Japan:
  90.  
  91.               RWZone::local(new RWZoneSimple(RWZone::Japan, RWZone::NoDST));
  92.  
  93.  
  94.  
  95.  
  96.  
  97.      For France:
  98.  
  99.               RWZone::local(new RWZoneSimple(RWZone::Europe, RWZone::WeEu));
  100.  
  101.  
  102.  
  103.  
  104.  
  105.      Here are the rules used internally for the RRRRWWWWZZZZoooonnnneeee::::::::NNNNooooAAAAmmmm and RRRRWWWWZZZZoooonnnneeee::::::::WWWWeeeeEEEEuuuu
  106.      values of RRRRWWWWZZZZoooonnnneeee::::::::DDDDssssttttRRRRuuuulllleeee:
  107.  
  108.               // last Sun in Apr to last in Oct:
  109.                const RWDaylightRule  usRuleAuld =
  110.                { 0, 0000, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
  111.           // first Sun in Apr to last in Oct
  112.                const RWDaylightRule usRule67 =
  113.                { &usRuleAuld, 1967, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };
  114.           // first Sun in Jan to last in Oct:
  115.                const RWDaylightRule usRule74 =
  116.                { &usRule67, 1974, 1, { 0, 0, 0, 120 }, { 9, 4, 0, 120 } };
  117.           // last Sun in Feb to last in Oct
  118.                const RWDaylightRule usRule75 =
  119.               { &usRule74, 1975, 1, { 1, 4, 0, 120 }, { 9, 4, 0, 120 } };
  120.           // last Sun in Apr to last in Oct
  121.                const RWDaylightRule usRule76 =
  122.                { &usRule75, 1976, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
  123.           // first Sun in Apr to last in Oct
  124.                const RWDaylightRule usRuleLate =
  125.                { &usRule76, 1987, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.           // last Sun in Mar to last in Sep
  141.                const RWDaylightRule euRuleLate =
  142.                { 0, 0000, 1, { 2, 4, 0, 120 }, { 8, 4, 0, 120 } };
  143.  
  144.  
  145.      Given these definitions,
  146.  
  147.               RWZone::local(new RWZoneSimple(RWZone::USCentral, &usRuleLate));
  148.  
  149.  
  150.  
  151.  
  152.  
  153.      is equivalent to the first example given above and repeated here:
  154.  
  155.               RWZone::local(new RWZoneSimple(RWZone::USCentral));
  156.  
  157.  
  158.  
  159.  
  160.  
  161.      Daylight-saving time systems that cannot be represented with
  162.      RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee and RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee must be modeled by deriving from RRRRWWWWZZZZoooonnnneeee
  163.      and implementing its virtual functions.  For example, under Britain's
  164.      Summer Time rules, alternate timekeeping begins the morning after the
  165.      third Saturday in April, unless that is Easter (in which case it begins
  166.      the week before) or unless the Council decides on some other time for
  167.      that year.  In some years Summer Time has been two hours ahead, or has
  168.      extended through winter without a break.  British Summer Time clearly
  169.      deserves an RRRRWWWWZZZZoooonnnneeee class all its own.
  170.  
  171. CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  172.               RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee(RWZone::StdZone zone,
  173.                        RWZone::DstRule = RWZone::NoAm);
  174.  
  175.  
  176.      Constructs an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee instance using internally held
  177.      RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeeessss.  This is the simplest interface to RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee.  The
  178.      first argument is the time zone for which an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee is to be
  179.      constructed.  The second argument is the daylight-saving time rule which
  180.      is to be followed.
  181.  
  182.               RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee(const RWDaylightRule* rule,
  183.                        long tzoff,  const RWCString& tzname,
  184.                        long altoff, const RWCString& altname);
  185.  
  186.  
  187.      Constructs an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee instance which daylight-saving time is
  188.      computed according to the rule specified.  Variables ttttzzzzooooffffffff and ttttzzzznnnnaaaammmmeeee are
  189.      the offset from UTC (in seconds, positive if west of 0 degrees longitude)
  190.      and the name of standard time.  Arguments aaaallllttttooooffffffff and aaaallllttttnnnnaaaammmmeeee are the
  191.      offset (typically equal to ttttzzzzooooffffffff ---- 3333666600000000) and name when daylight-saving
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      time is in effect.  If rrrruuuulllleeee is zero, daylight-saving time is not
  207.      observed.
  208.  
  209.               RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee(long tzoff, const RWCString& tzname);
  210.  
  211.  
  212.      Constructs an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee instance in which daylight-saving time is not
  213.      observed.  Argument ttttzzzzooooffffffff is the offset from UTC (in seconds, positive if
  214.      west of 0 degrees longitude) and ttttzzzznnnnaaaammmmeeee is the name of the zone.
  215.  
  216.               RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee(RWZone::StdZone zone,
  217.                        const RWDaylightRule* rule);
  218.  
  219.  
  220.      Constructs an RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee instance in which offsets and names are
  221.      specified by the SSSSttttddddZZZZoooonnnneeee argument.  Daylight-saving time is computed
  222.      according to the rrrruuuulllleeee argument, if non-zero; otherwise, DST is not
  223.      observed.
  224.  
  225. ssssttttrrrruuuucccctttt RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee
  226.      The RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee struct passed to RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee's constructor can be a
  227.      single rule for all years or can be the head of a chain of rules going
  228.      backwards in time.  RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttRRRRuuuulllleeee is a struct with no constructors.  It
  229.      can be initialized with the syntax used in the Examples section above.
  230.      The data members of this structure are as follows:
  231.  
  232.               struct RWExport RWDaylightRule {
  233.  
  234.  
  235.  
  236.                 RWDaylightRule const* next_;
  237.             short firstYear_;
  238.             char observed_;
  239.             RWDaylightBoundary begin_;
  240.             RWDaylightBoundary end_;
  241.           }
  242.  
  243.  
  244.  
  245.               RWDaylightRule const*
  246.           nnnneeeexxxxtttt____;
  247.  
  248.  
  249.      Points to the next rule in a chain which continues backwards in time.
  250.  
  251.               short
  252.           ffffiiiirrrrssssttttYYYYeeeeaaaarrrr____;
  253.  
  254.  
  255.      Four digit representation of the year in which this rule first goes into
  256.      effect.
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               char
  273.           oooobbbbsssseeeerrrrvvvveeeedddd____;
  274.  
  275.  
  276.      A boolean value that can be used to specify a period of years for which
  277.      daylight-saving time is not observed.  1111 = Daylight-saving time is in
  278.      effect during this period 0000 = Daylight-saving time is nnnnooootttt in effect
  279.      during this period (Note that these are numeric values as distinguished
  280.      from '1111' and '0000'.)
  281.  
  282.               RWDaylightBoundary
  283.           bbbbeeeeggggiiiinnnn____;
  284.  
  285.  
  286.      This structure indicates the time of year, to the minute, when DST begins
  287.      during this period.  (See RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttBBBBoooouuuunnnnddddaaaarrrryyyy below.)
  288.  
  289.               RWDaylightBoundary
  290.           eeeennnndddd____;
  291.  
  292.  
  293.      This structure indicates the time of year, to the minute, when standard
  294.      time resumes during this period.  (See RRRRWWWWDDDDaaaayyyylllliiiigggghhhhttttBBBBoooouuuunnnnddddaaaarrrryyyy below.)
  295.  
  296. ssssttttrrrruuuucccctttt RRRRWWWWDDDDaaaayyyylllliiiigggghhhhtttt----BBBBoooouuuunnnnddddaaaarrrryyyy
  297.               struct RWExport RWDaylightBoundary {
  298.  
  299.  
  300.  
  301.                 // this struct uses <time.h> struct tm conventions:
  302.             int month_;    // [0..11]
  303.             int week_;     // [0..4], or -1
  304.             int weekday_;  // [0..6], 0=Sunday; or, [1..31] if week_== -1
  305.             int minute_;   // [0..1439]  (Usually 2 AM, = 120)
  306.           };
  307.  
  308.  
  309.               int
  310.           mmmmoooonnnntttthhhh____;
  311.  
  312.  
  313.      The month from ((((0000 ---- 11111111), where 0000 = January.
  314.  
  315.               int
  316.           wwwweeeeeeeekkkk____;
  317.  
  318.  
  319.      A week of the month from (0000 ---- 4444), or ----1111 if the following field is to
  320.      represent a day within the month.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))                                          RRRRWWWWZZZZoooonnnneeeeSSSSiiiimmmmpppplllleeee((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               int
  339.           wwwweeeeeeeekkkkddddaaaayyyy____;
  340.  
  341.  
  342.      A day of the week from (0000 ---- 6666), where 0000 = Sunday, or, if the wwwweeeeeeeekkkk____ field
  343.      is ----1111, a day of the month from (1111 ---- 33331111).
  344.  
  345.               int
  346.           mmmmiiiinnnnuuuutttteeee____;
  347.  
  348.  
  349.      Minutes after 12:00 AM, from (0000 ---- 1111444433339999).  For example,  111122220000 = 2 AM.
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.